package com.ruoyi.web.controller.project;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.Teacher;
import com.ruoyi.project.service.ITeacherService;
import com.ruoyi.web.core.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;

/**
 * 教师档案 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-01
 */
@Controller
@RequestMapping("/project/teacher")
public class TeacherController extends BaseController
{
    private String prefix = "project/teacher";
	
	@Autowired
	private ITeacherService teacherService;
	
	@RequiresPermissions("project:teacher:view")
	@GetMapping()
	public String teacher()
	{
	    return prefix + "/teacher";
	}


	@RequiresPermissions("project:teacher:view")
	@GetMapping("/data")
	public String teacherData()
	{
		return prefix + "/teacher_data";
	}
	/**
	 * 查询教师档案列表
	 */
	@RequiresPermissions("project:teacher:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Teacher teacher)
	{
		startPage();
        List<Teacher> list = teacherService.selectTeacherList(teacher);
		return getDataTable(list);
	}
	
	/**
	 * 新增教师档案
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存教师档案
	 */
	@RequiresPermissions("project:teacher:add")
	@Log(title = "教师档案", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Teacher teacher)
	{		
		return toAjax(teacherService.insertTeacher(teacher));
	}

	/**
	 * 修改教师档案
	 */
	@GetMapping("/edit/{teacherId}")
	public String edit(@PathVariable("teacherId") Long teacherId, ModelMap mmap)
	{
		Teacher teacher = teacherService.selectTeacherById(teacherId);
		mmap.put("teacher", teacher);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存教师档案
	 */
	@RequiresPermissions("project:teacher:edit")
	@Log(title = "教师档案", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Teacher teacher)
	{		
		return toAjax(teacherService.updateTeacher(teacher));
	}
	
	/**
	 * 删除教师档案
	 */
	@RequiresPermissions("project:teacher:remove")
	@Log(title = "教师档案", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(teacherService.deleteTeacherByIds(ids));
	}
	
}
